package com.server.questionbank.snframe.mapper.Course;

import com.server.questionbank.snframe.domain.Course.TKnowledge;
import com.server.questionbank.snframe.domain.QuestionBank.Knowledge;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TKnowledgeMapper {
    // 根据recordId查询知识点
    @Select("SELECT * FROM T_knowledge WHERE record_id = #{recordId}")
    public List<Knowledge> getKnowledgeById(Long recordId);

    // 根据courseId查询知识点
    @Select("SELECT * FROM T_knowledge WHERE course_id = #{courseId}")
    public List<Knowledge> getKnowledgeByCourseId(Long courseId);

    // 根据cameraId查询知识点
    @Select("SELECT * FROM T_knowledge WHERE camera_id = #{cameraId}")
    public List<Knowledge> getKnowledgeByCameraId(Long cameraId);

    // 根据courseId和cameraId查询知识点
    @Select("SELECT * FROM T_knowledge WHERE course_id = #{courseId} AND camera_id = #{cameraId}")
    public List<Knowledge> getKnowledgeByCourseIdAndCameraId(Long courseId, Long cameraId);

    // 根据quoteRecordId查询知识点
    @Select("SELECT * FROM T_knowledge WHERE quote_record_id = #{quoteRecordId}")
    public List<Knowledge> getKnowledgeByQuoteRecordId(Long quoteRecordId);

    // 根据exercisesId查询知识点
    @Select("SELECT T_knowledge.* FROM T_knowledge, exec_knowledge WHERE exec_knowledge.record_id = T_knowledge.record_id AND exec_knowledge.exercises_id = #{exercisesId}")
    public List<Knowledge> getKnowledgeByExercisesId(Long exercisesId);

    // 创建知识点
    @Insert("INSERT INTO T_knowledge ( " +
            "            course_id, camera_id, quote_record_id, " +
            "            quote_time, record_type, record_url, knowledge_content, " +
            "            file_size, is_public, upload_by, upload_time, " +
            "            record_remark " +
            "        ) VALUES ( " +
            "            #{knowledge.courseId}, #{knowledge.cameraId}, #{knowledge.quoteRecordId}, " +
            "            #{knowledge.quoteTime}, #{knowledge.recordType}, #{knowledge.recordUrl}, #{knowledge.knowledgeContent}, " +
            "            #{knowledge.fileSize}, #{knowledge.isPublic}, #{knowledge.uploadBy}, #{knowledge.uploadTime}, " +
            "            #{knowledge.recordRemark} " +
            "        )"
    )
    public Long createKnowledge(@Param("knowledge") TKnowledge knowledge);

    // 删除知识点
    @Delete("DELETE FROM T_knowledge WHERE record_id = #{recordId}")
    public Long removeKnowledge(Long recordId);
}
